import { instance } from "./api.interceptor"
import { ICreateLesson, ILesson, IUpdateLesson } from "../interfaces"


export const LessonService = {
    async getByThemeId(themeId: number): Promise<ILesson[]> {
        const resp = await instance.get<ILesson[]>(`/lesson/by-theme-id/${themeId}`)
        return resp.data
    },

    async getOne(lectureId: number): Promise<ILesson> {
        const resp = await instance.get<ILesson>(`/lesson/${lectureId}`)
        return resp.data
    },

    async getAll(): Promise<ILesson[]> {
        const resp = await instance.get<ILesson[]>(`/lesson`)
        return resp.data
    },

    async create(dto: ICreateLesson): Promise<ILesson> {
        const resp = await instance.post<ILesson>('/lesson', dto)
        return resp.data
    },
    async update(data: {id: number, dto: IUpdateLesson}) {
        const resp = await instance.patch<ILesson>(`/lesson/${data.id}`, data.dto)
        return resp.data
    },

    async remove(id: number): Promise<ILesson> {
        const resp = await instance.delete<ILesson>(`/lesson/${id}`)
        return resp.data
    }

}
